I am trying to create a string with where i want to have the following
for and array ['john','harry', 'darren']
i expect below
e.g john harry and daren
is it even a valid case for internationalisation or am i better off just programming do this?
You may create a function, and the body will look something like this:
function myFunc (a) {
if (a.length > 1) {
const exceptLast = a.slice(0, -1)
let last = a.slice(-1)
last = ['and', ...last]
return [...exceptLast, ...last].join(" ")
}
return a[0]
}
Test it like this:
const da = ['b', 'cc', 'ddd']
const da1 = ['b']
const da2 = ['b']
console.log(myFunc(da))
console.log(myFunc(da1))
console.log(myFunc(da2))